# -*- coding: utf-8 -*-
# File : datetime_utils.py
# Author: taoyahui
# Date : 2021/10/18
from datetime import date, datetime, timedelta
import json


class ComplexEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj, date):
            return obj.strftime('%Y-%m-%d')
        else:
            return json.JSONEncoder.default(self, obj)


def time_delta_gen(start, end, delta):
    curr = start
    while curr < end:
        yield curr
        curr += delta


